/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.pe.siass.utils;

import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 *
 * @author Hrengifo
 */
public class USqlMapLoader {

     /* Instancia de SqlMapLoader*/
    private static SqlSessionFactory sqlMapper;
    private static USqlMapLoader instancia;
    private Reader reader = null;
    private static String IBATIS_XML_CONFIG_FILE = "com/pe/siass/resources/iBatisConfig.xml";

    private USqlMapLoader() throws IOException {
        String resource = IBATIS_XML_CONFIG_FILE;
        reader = Resources.getResourceAsReader(resource);
        sqlMapper = new SqlSessionFactoryBuilder().build(reader);
    }

    public static USqlMapLoader getInstance() throws IOException {
        if (instancia == null) {
            return new USqlMapLoader();
        }
        return instancia;
    }
    
    public SqlSessionFactory getSession(){
        return sqlMapper;
    }

}
